<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('产品销量统计列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>厂家名称：</label>
                                <input type="text" name="factoryName"/>
                            </li>
                            <li>
                                <label>产品名称：</label>
                                <input type="text" name="partsName"/>
                            </li>
                            <li>
                                <label>规格名称：</label>
                                <input type="text" name="attributeName"/>
                            </li>
                            <li>
                                <label>统计年份：</label>
                                <input id="periodYear" type="text" name="periodYear"/>
                            </li>
                            <li>
                                <label>统计月份：</label>
                                <input id="periodMonth" type="text" name="periodMonth"/>
                            </li>
                            <li>
                                <label>是否核算：</label>
                                <select name="isCheck" th:with="type=${@dict.getType('zsyh_yesno')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <!--<div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="zsyh:partsSales:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="zsyh:partsSales:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="zsyh:partsSales:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="zsyh:partsSales:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>-->

            <!--if (options.striped) {
            target.addClass('table-striped');
            }
            if (options.bordered) {
            target.addClass('table-bordered');
            }
            if (options.hover) {
            target.addClass('table-hover');
            }
            if (options.condensed) {
            target.addClass('table-condensed');
            }-->

            <div class="col-sm-12 select-table table-hover">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('zsyh:partsSales:edit')}]];
        var removeFlag = [[${@permission.hasPermi('zsyh:partsSales:remove')}]];
        var isCheckDatas = [[${@dict.getType('zsyh_yesno')}]];
        var prefix = ctx + "zsyh/partsSales";
        //获取当前年月
        var myDate = new Date();
        $("#periodYear").val(myDate.getFullYear());
        $("#periodMonth").val(myDate.getMonth()+1);
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                showFooter: true,
                modalName: "产品销量统计",
                columns: [{
                    field : 'Number',
                    title : '序号',
                    align: 'center',
                    width: 20,
                    formatter : function(value, row, index) {
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                    }
                },
                {
                    field: 'id',
                    title: '主键',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'factoryName',
                    align: 'center',
                    title: '厂家名称'
                },
                    {
                        field: 'attributeLogo',
                        align: 'center',
                        title: '主图',
                        formatter: function (value, row, index) {
                            return $.table.imageView(value);
                        }
                    },
                {
                    field: 'partsName',
                    align: 'center',
                    title: '产品名称'
                },
                {
                    field: 'attributeName',
                    align: 'center',
                    title: '规格名称'
                },
                {
                    field: 'bookNum',
                    align: 'center',
                    title: '预定量',
                    footerFormatter:function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            if(value[i].bookNum != null && value[i].bookNum != '' && value[i].bookNum != undefined){
                                sumBalance += parseFloat(value[i].bookNum);
                            }
                        }
                        return "合计预定量：" + sumBalance.toFixed(2);
                    }
                },{
                    field: 'bookMoney',
                    align: 'center',
                    title: '预定金额',
                    footerFormatter:function (value) {
                        var sumBookMoney =0;
                        for (var i in value) {
                            if(value[i].bookMoney != null && value[i].bookMoney != '' && value[i].bookMoney != undefined){
                                sumBookMoney += parseFloat(value[i].bookMoney);
                            }
                        }
                        return "合计预定金额：" + sumBookMoney.toFixed(2);
                    }
                },
                {
                    field: 'deliveryNum',
                    align: 'center',
                    title: '发货量',
                    footerFormatter:function (value) {
                        var sumBalance1 = 0;
                        for (var i in value) {
                            if(value[i].deliveryNum != null && value[i].deliveryNum != '' && value[i].deliveryNum != undefined){
                                sumBalance1 += parseFloat(value[i].deliveryNum);
                            }
                        }
                        return "合计发货量：" + sumBalance1.toFixed(2);
                    }
                },{
                    field: 'deliveryMoney',
                    align: 'center',
                    title: '发货金额',
                    footerFormatter:function (value) {
                        var sumDeliveryMoney =0;
                        for (var i in value) {
                            if(value[i].deliveryMoney != null && value[i].deliveryMoney != '' && value[i].deliveryMoney != undefined){
                                sumDeliveryMoney += parseFloat(value[i].deliveryMoney);
                            }
                        }
                        return "合计发货金额：" + sumDeliveryMoney.toFixed(2);
                    }
                },
                {
                    field: 'periodYear',
                    align: 'center',
                    title: '统计年份'
                },
                {
                    field: 'periodMonth',
                    align: 'center',
                    title: '统计月份'
                },
                {
                    field: 'isCheck',
                    align: 'center',
                    title: '是否核算',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isCheckDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.isCheck == "0"){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="createCheck(\'' + row.id + '\')"><i class="fa fa-edit"></i>开始核算</a> ');
                        }
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="viewRelateOrder(\'' + row.attributeId + '\',\''+row.periodYear+'\',\''+row.periodMonth+'\')"><i class="fa fa-history"></i>查看详细订单</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function createCheck(id) {
            var url = ctx + 'zsyh/partsRebate/addBySalesId?salesId='+id;
            $.modal.open("开始核算", url, '1000', '500');
        }

        function viewRelateOrder(attributeId,periodYear,periodMonth) {
            var url =prefix + '/viewSales?attributeId='+attributeId+"&periodYear="+periodYear+"&periodMonth="+periodMonth;
            $.modal.open("查看详细订单", url, '1000', '500');
        }

    </script>
</body>
</html>